﻿$(document).ready(function () {

    var map = null;
    function LoadMap() {

        map = new Microsoft.Maps.Map(
            document.getElementById('myMap'),
            {
                credentials: "AvW00CilYAUa8-GrAXIZl9dT6FL6-I73IOUxFk6xrsqUZ0T4vZZPdL787K02to-I",
                center: new Microsoft.Maps.Location(-30.03, -51.21),
                mapTypeId: Microsoft.Maps.MapTypeId.road,
                zoom: 8,
                showScalebar: false,
                showMapTypeSelector: false,
            });
    }
    LoadMap();

    $('#btnShowLocations').click(function () {
        var url = "/ConsultaMedicos/GetLocations";
        $.getJSON(url, null, function (data) {
            $.each(data, function (index, LocationData) {

                //The Bing Maps API's does not currently turn on all point of interest data on the map layer. 
                //The reason for this is most users of the API's are companies and the last thing any company 
                //wants is to show a competitor on their website via the map.
                var loc = new Microsoft.Maps.Location(LocationData.latitude, LocationData.longitude);
                var pin = new Microsoft.Maps.Pushpin(loc);

                map.entities.push(pin);
                map.setView({ center: loc, zoom: 15 });
            });
        });
    });

});